package cn.stylefeng.guns.modular.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.Feedback;
import cn.stylefeng.guns.modular.entity.FeedbackClass;
import cn.stylefeng.guns.modular.mapper.FeedbackClassMapper;
import cn.stylefeng.guns.modular.service.IFeedbackClassService;
import cn.stylefeng.guns.modular.util.IdWorker;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * <p>
 * 反馈分类表 服务实现类
 * </p>
 *
 * @author XiangTianGe
 * @since 2020-04-09
 */
@Service
public class FeedbackClassServiceImpl extends ServiceImpl<FeedbackClassMapper, FeedbackClass> implements IFeedbackClassService {

    @Autowired
    private FeedbackClassMapper feedbackClassMapper;

    @Autowired
    private IdWorker idWorker;

    /**
     * 获取分类列表
     */
    @Override
    public LayuiPageInfo getList(Page page) {
        IPage<Feedback> iPage = null;
        return LayuiPageFactory.createPageInfo(iPage);
    }

    /**
     * 新增类别
     */
    @Override
    public void addClass(FeedbackClass feedbackClass) {
        feedbackClass.setCreatedAt(new Date());
        feedbackClass.setClassId(idWorker.nextId());
        feedbackClassMapper.insert(feedbackClass);
    }

    /**
     * 修改类别
     */
    @Override
    public void updateClass(FeedbackClass feedbackClass) {
        feedbackClass.setCreatedAt(new Date());
        feedbackClassMapper.updateById(feedbackClass);
    }

    /**
     * 删除
     */
    @Override
    public void delete(Long classId) {
        feedbackClassMapper.deleteById(classId);
    }

    /**
     * 跳转修改页面
     */
    @Override
    public ModelAndView updateId(Long id) {
        ModelAndView modelAndView = new ModelAndView();
        FeedbackClass feedbackClass = feedbackClassMapper.selectById(id);
        modelAndView.addObject("feedbackClass", feedbackClass);
        return modelAndView;
    }

}
